Modification start date
[BattleCats.git] / Assets / Scripts / UI Scripts / UpgradeUI.cs
blobf41e0d3eed3a7645f27cb99f7465df98ab83ff88
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.SceneManagement;
5 using UnityEngine.UI;
6 using UnityEngine.EventSystems;
8 public class UpgradeUI : MonoBehaviour {
10 [SerializeField]
11 GameObject upgradePanel;
12 [SerializeField]
13 GameObject successPanel;
15 [SerializeField]
16 GameObject successPanelYes;
19 //health upgrade panel
20 [SerializeField]
21 GameObject shipHealthPanel;
22 [SerializeField]
23 GameObject shipHealthButton1;
24 [SerializeField]
25 Button ammoButton1;
26 [SerializeField]
27 Button shipMovementButton1;
28 [SerializeField]
29 GameObject health1Upgrade;
30 [SerializeField]
31 Text health1Price;
32 [SerializeField]
33 GameObject health2Upgrade;
34 [SerializeField]
35 Text health2Price;
36 [SerializeField]
37 GameObject health3Upgrade;
38 [SerializeField]
39 Text health3Price;
43 //ammo panel
44 [SerializeField]
45 GameObject ammoPanel;
46 [SerializeField]
47 Button shipHealthButton2;
48 [SerializeField]
49 GameObject ammoButton2;
50 [SerializeField]
51 Button shipMovementButton2;
52 [SerializeField]
53 GameObject ammo1Upgrade;
54 [SerializeField]
55 Text ammo1Price;
56 [SerializeField]
57 GameObject ammo2Upgrade;
58 [SerializeField]
59 Text ammo2Price;
63 //shipmovement panel
64 [SerializeField]
65 GameObject shipMovementPanel;
66 [SerializeField]
67 Button shipHealthButton3;
68 [SerializeField]
69 Button ammoButton3;
70 [SerializeField]
71 GameObject shipMovementButton3;
72 [SerializeField]
73 GameObject movement1Upgrade;
74 [SerializeField]
75 Text movement1Price;
76 [SerializeField]
77 GameObject movement2Upgrade;
78 [SerializeField]
79 Text movement2Price;
86 [SerializeField]
87 GameObject confirmationPanel;
89 [SerializeField]
90 GameObject yesButton;
92 [SerializeField]
93 Button noButton;
95 [SerializeField]
96 Text moneyText;
99 public float upgradeWindowDelay;
100 public float successWindowDelay;
103 public static bool startNextLevel;
104 private GameManager gameManager;
105 private HealthSlider hp;
106 private StationNav stationNav;
107 private float upgardeWindowTimer = 0;
108 private float successWindowTimer = 0;
109 private bool canDisplayUpgrade=true;
111 // Use this for initialization
112 void Start () {
113 startNextLevel = false;
114 shipHealthPanel.SetActive(true);
115 ammoPanel.SetActive(false);
116 shipMovementPanel.SetActive(false);
117 shipHealthButton1.GetComponent<Button>().interactable = false;
118 confirmationPanel.SetActive(false);
119 GameObject gameManagerObject = GameObject.FindWithTag("GameManager");
120 if (gameManagerObject)
122 gameManager = gameManagerObject.GetComponent<GameManager>();
124 GameObject hpObject = GameObject.FindGameObjectWithTag("YarnPhysics");
125 if (hpObject)
127 hp = hpObject.GetComponent<HealthSlider>();
129 GameObject navGameObject = GameObject.FindGameObjectWithTag("NavigationStation");
130 if (navGameObject)
132 stationNav = navGameObject.GetComponent<StationNav>();
135 health1Price.text = movement1Price.text = ammo1Price.text = GameManager.priceList[0].ToString();
136 health2Price.text = movement2Price.text = ammo2Price.text = GameManager.priceList[1].ToString();
137 health3Price.text = GameManager.priceList[2].ToString();
138 SetButtonInteactive();
141 // Update is called once per frame
142 void Update () {
143 moneyText.text = GameManager.money.ToString();
144 if (!(gameManager.HelloGrandma()) && hp.LevelEnded && !upgradePanel.activeSelf&&canDisplayUpgrade)
146 if(upgardeWindowTimer>=upgradeWindowDelay)
148 activateUpgradePanel();
149 upgardeWindowTimer = 0;
151 else
153 upgardeWindowTimer += Time.deltaTime;
156 else if((gameManager.HelloGrandma()) && hp.BossEnded && !successPanel.activeSelf)
158 if (successWindowTimer >= successWindowDelay)
160 activateSuccessPanel();
161 successWindowTimer = 0;
163 else
165 successWindowTimer += Time.deltaTime;
170 private void activateUpgradePanel()
172 upgradePanel.SetActive(true);
173 EventSystem.current.SetSelectedGameObject(shipHealthButton1, null);
177 private void activateSuccessPanel()
179 successPanel.SetActive(true);
180 EventSystem.current.SetSelectedGameObject(successPanelYes, null);
183 public void shipHealthPanelActive()
185 if(!shipHealthPanel.activeSelf)
187 shipHealthPanel.SetActive(true);
188 ammoPanel.SetActive(false);
189 shipMovementPanel.SetActive(false);
190 shipHealthButton1.GetComponent<Button>().interactable = false;
191 EventSystem.current.SetSelectedGameObject(shipHealthButton1, null);
192 ammoButton1.interactable = true;
193 shipMovementButton1.interactable = true;
196 public void ammoPanelActive()
198 if (!ammoPanel.activeSelf)
200 ammoPanel.SetActive(true);
201 shipHealthPanel.SetActive(false);
202 shipMovementPanel.SetActive(false);
203 ammoButton2.GetComponent<Button>().interactable = false;
204 EventSystem.current.SetSelectedGameObject(ammoButton2, null);
205 shipHealthButton2.interactable = true;
206 shipMovementButton2.interactable = true;
211 public void shipMovementPanelActive()
213 if (!shipMovementPanel.activeSelf)
215 shipMovementPanel.SetActive(true);
216 ammoPanel.SetActive(false);
217 shipHealthPanel.SetActive(false);
218 shipMovementButton3.GetComponent<Button>().interactable = false;
219 EventSystem.current.SetSelectedGameObject(shipMovementButton3, null);
220 shipHealthButton3.interactable = true;
221 ammoButton3.interactable = true;
226 public void closeUpgradePanel()
228 upgradePanel.SetActive(false);
229 confirmationPanel.SetActive(true);
230 EventSystem.current.SetSelectedGameObject(yesButton, null);
231 canDisplayUpgrade = false;
234 public void GoToMainMenu()
236 GameObject menuManager = GameObject.FindGameObjectWithTag ("MenuManager");
237 if (menuManager != null)
239 MenuManager menuManagerScript = menuManager.GetComponent<MenuManager> ();
240 menuManagerScript.PlayMenuSel ();
241 menuManagerScript.StartMenuMusic ();
243 SceneManager.LoadScene("MainMenu");
246 public void YesButtonClicked()
248 startNextLevel = true;
249 confirmationPanel.SetActive(false);
250 //upgradePanel.SetActive(false);
253 public void NoButtonClicked()
255 confirmationPanel.SetActive(false);
256 upgradePanel.SetActive(true);
257 shipHealthPanel.SetActive(true);
258 ammoPanel.SetActive(false);
259 shipMovementPanel.SetActive(false);
260 canDisplayUpgrade = true;
261 EventSystem.current.SetSelectedGameObject(shipHealthButton1, null);
266 public void QuitGame()
268 Application.Quit();
272 public void healthUpdate1()
274 Navigation nonNav = new Navigation();
275 nonNav.mode = Navigation.Mode.None;
276 if (GameManager.money >= GameManager.priceList[0])
278 health1Upgrade.GetComponent<Button>().navigation = nonNav;
279 health1Upgrade.GetComponent<Button>().interactable = false;
280 health2Upgrade.GetComponent<Button>().interactable = true;
281 EventSystem.current.SetSelectedGameObject(health2Upgrade, null);
282 hp.UpgradeMaxHealth(GameManager.healthUpgradeValue[0]);
283 gameManager.spendCoin(GameManager.priceList[0]);
284 PlayCoinSound ();
285 GameManager.healthUpgradeAvailability[0] = false;
286 GameManager.healthUpgradeAvailability[1] = true;
291 public void healthUpdate2()
293 Navigation nonNav = new Navigation();
294 nonNav.mode = Navigation.Mode.None;
295 if (GameManager.money >= GameManager.priceList[1])
297 health2Upgrade.GetComponent<Button>().navigation = nonNav;
298 health2Upgrade.GetComponent<Button>().interactable = false;
299 health3Upgrade.GetComponent<Button>().interactable = true;
300 EventSystem.current.SetSelectedGameObject(health3Upgrade, null);
301 hp.UpgradeMaxHealth(GameManager.healthUpgradeValue[1]);
302 gameManager.spendCoin(GameManager.priceList[1]);
303 PlayCoinSound ();
304 GameManager.healthUpgradeAvailability[1] = false;
305 GameManager.healthUpgradeAvailability[2] = true;
310 public void healthUpdate3()
312 Navigation nonNav = new Navigation();
313 nonNav.mode = Navigation.Mode.None;
314 if (GameManager.money >= GameManager.priceList[2])
316 health3Upgrade.GetComponent<Button>().navigation = nonNav;
317 health3Upgrade.GetComponent<Button>().interactable = false;
318 EventSystem.current.SetSelectedGameObject(shipHealthButton1, null);
319 hp.UpgradeMaxHealth(GameManager.healthUpgradeValue[2]);
320 gameManager.spendCoin(GameManager.priceList[2]);
321 PlayCoinSound ();
322 GameManager.healthUpgradeAvailability[2] = false;
326 public void ammoUpgrade1()
328 Navigation nonNav = new Navigation();
329 nonNav.mode = Navigation.Mode.None;
330 if (GameManager.money >= GameManager.priceList[0])
332 ammo1Upgrade.GetComponent<Button>().navigation = nonNav;
333 ammo1Upgrade.GetComponent<Button>().interactable = false;
334 ammo2Upgrade.GetComponent<Button>().interactable = true;
335 EventSystem.current.SetSelectedGameObject(ammo2Upgrade, null);
336 GameManager.ammoTypeUnlocked[0] = true;
337 gameManager.spendCoin(GameManager.priceList[0]);
338 PlayCoinSound ();
339 GameManager.ammoUpgradeAvailability[0] = false;
340 GameManager.ammoUpgradeAvailability[1] = true;
344 public void ammoUpgrade2()
346 Navigation nonNav = new Navigation();
347 nonNav.mode = Navigation.Mode.None;
348 if (GameManager.money >= GameManager.priceList[1])
350 ammo2Upgrade.GetComponent<Button>().navigation = nonNav;
351 ammo2Upgrade.GetComponent<Button>().interactable = false;
352 EventSystem.current.SetSelectedGameObject(ammoButton2, null);
353 GameManager.ammoTypeUnlocked[1] = true;
354 gameManager.spendCoin(GameManager.priceList[1]);
355 PlayCoinSound ();
356 GameManager.ammoUpgradeAvailability[1] = false;
361 public void movementUpdate1()
363 Navigation nonNav = new Navigation();
364 nonNav.mode = Navigation.Mode.None;
365 if (GameManager.money >= GameManager.priceList[0])
367 movement1Upgrade.GetComponent<Button>().navigation = nonNav;
368 movement1Upgrade.GetComponent<Button>().interactable = false;
369 movement2Upgrade.GetComponent<Button>().interactable = true;
370 EventSystem.current.SetSelectedGameObject(movement2Upgrade, null);
371 stationNav.UpgradeTorque(GameManager.torqueIncrease);
372 gameManager.spendCoin(GameManager.priceList[0]);
373 PlayCoinSound ();
374 GameManager.movementUpgradeAvailability[0] = false;
375 GameManager.movementUpgradeAvailability[1] = true;
381 public void movementUpgrade2()
383 Navigation nonNav = new Navigation();
384 nonNav.mode = Navigation.Mode.None;
385 if (GameManager.money >= GameManager.priceList[1])
387 movement2Upgrade.GetComponent<Button>().navigation = nonNav;
388 movement2Upgrade.GetComponent<Button>().interactable = false;
389 EventSystem.current.SetSelectedGameObject(shipMovementButton3, null);
390 hp.UpGradeInvulnerability(GameManager.invulnerabilityTimerIncrease);
391 gameManager.spendCoin(GameManager.priceList[1]);
392 PlayCoinSound ();
393 GameManager.movementUpgradeAvailability[1] = false;
398 private void SetButtonInteactive()
400 health1Upgrade.GetComponent<Button>().interactable = GameManager.healthUpgradeAvailability[0];
401 health2Upgrade.GetComponent<Button>().interactable = GameManager.healthUpgradeAvailability[1];
402 health3Upgrade.GetComponent<Button>().interactable = GameManager.healthUpgradeAvailability[2];
403 ammo1Upgrade.GetComponent<Button>().interactable = GameManager.ammoUpgradeAvailability[0];
404 ammo2Upgrade.GetComponent<Button>().interactable = GameManager.ammoUpgradeAvailability[1];
405 movement1Upgrade.GetComponent<Button>().interactable = GameManager.movementUpgradeAvailability[0];
406 movement2Upgrade.GetComponent<Button>().interactable = GameManager.movementUpgradeAvailability[1];
409 public void PlayCoinSound()
411 GameObject ExtraSFX = GameObject.FindGameObjectWithTag ("ExtraSFX");
412 AudioSource[] audioSources = ExtraSFX.GetComponents<AudioSource> ();
413 AudioSource coinSound = audioSources [2];
414 coinSound.Play ();